﻿using System;
using System.Security.Principal;

namespace Toodledo.Security
{
    public class ToodledoIdentity : IIdentity
    {
        private readonly bool _isAuthenticated;
        public string Userid { get; set; }
        public string UserName { get; set; }
        public string UserEmail { get; set; }
        public string Password { private get; set; }

        public string AuthKey { get; set; }
        public DateTime AuthExpiryTime { get; set; }
        public string Token { get; set; }

        public ToodledoIdentity(string userEmail, string password, string userId, string token, string authKey)
        {
            if (String.IsNullOrEmpty(userId))
                throw new ArgumentException("userId is null or empty.", "userId");
            if (String.IsNullOrEmpty(userEmail))
                throw new ArgumentException("userEmail is null or empty.", "userEmail");
            if (String.IsNullOrEmpty(token))
                throw new ArgumentException("token is null or empty.", "token");
            if (String.IsNullOrEmpty(authKey))
                throw new ArgumentException("authKey is null or empty.", "authKey");
            if (String.IsNullOrEmpty(password))
                throw new ArgumentException("password is null or empty.", "password");

            Userid = userId;
            UserEmail = userEmail;
            AuthKey = authKey;
            Password = password;
            Token = token;
            _isAuthenticated = true;
        }

        #region IIdentity Members

        public string AuthenticationType
        {
            get { return "ToodledoToken"; }
        }

        public bool IsAuthenticated
        {
            get { return _isAuthenticated; }
        }

        public string Name
        {
            get { return string.IsNullOrEmpty(UserName)? UserEmail: UserName; }
        }
        #endregion
    }
}
